<?php
	class uploadClass
	{
		private $uploadDirectory, $fileName, $fileSize;
		private $allowedExtensions = array 
		(
			'zip'	=> true,
			'7z'	=> true,
			'rar'	=> true,	
			'txt'	=> true,
			'pdf'	=> true,
			'doc' 	=> true,
			'docx' 	=> true,
			'xls'	=> true,
			'ppt'	=> true,	  
			'exe'	=> false,	
			'gif'	=> true,
			'png'	=> true,
			'jpg'	=> true,
			'jpeg'	=> true,
			'mp3'	=> true,
			'mp4'	=> true,
		);
		
		function __construct($uploadDirectory,$banList=array())
		{
			$this->setupDirectory($uploadDirectory);
			$this->setBanExtension($banList);
		}
		
		private function setupDirectory($uploadDirectory)
		{
			if (!file_exists($uploadDirectory))
			{
				makeFullPath($uploadDirectory);
			}
			$this->uploadDirectory = $uploadDirectory;
		}
		
		private function setBanExtension($banList)
		{
			foreach ($banList as $row)
			{
				$allowedExtensions[$row] = false;
			}
		}
		
		public function upload($file)
		{
			$this->fileName = $file['name'];
			$this->fileSize = $file['size'];
			
			if ($this->checkExtension() && $this->checkSize())
			{
				if (file_exists($this->uploadDirectory.$this->fileName))
				{
					return false;
				}
				else 
				{
					return move_uploaded_file($file['tmp_name'], $this->uploadDirectory.$this->fileName);
				}
			}
			return false;
		}
		
		private function checkExtension()
		{
			$extension = strtolower(substr($this->fileName, strripos($this->fileName, '.') + 1));
			return (isset($this->allowedExtensions[$extension]) && $this->allowedExtensions[$extension]);
		}
		
		private function checkSize()
		{
			return ($this->fileSize <= uploadSize);
		}
	}